/*
* 相仿的商品(猜你喜欢)
* */
import AppConfig from '../config/appConfig';
import ShopItem from './shopItem';
import axiosUtil from "../utils/axiosUtil";
import AppStore from "../store/appStore";
import {TimeStamp} from "../utils/utils";
import viewUtil from "../utils/viewUtil";
import {CreateHaoDanwangList, CreateJinDongXiangList} from "./modeCtr";
import hotSearch from '../store/hotSearchStore';

export function GetSimilar(item) {
  if (item.TypeFrom === AppConfig.TaoBao){
    return TaoBao(item)
  }
  if (item.TypeFrom === AppConfig.JinDong){
    return JinDong(item);
  }
  if (item.TypeFrom === AppConfig.PingDuoDuo){
    return PingDuoDuo(item);
  }
  return new Promise(resolve => {
    resolve(null);
  })
}

function TaoBao(item) {
  return TaoBao_haoDanWang(item)
}

function TaoBao_haoDanWang(item) {
  return new  Promise(resolve => {
    const url = AppStore.data.taoBaoApi.Similar.format(AppStore.data.taoBaoApi.haoDanKey,item.Id)
    axiosUtil.get(url).then(res=>{
       if (res.code !== 1){
         viewUtil.ShowToast('服务器错误～');
      }else{
         let ttt = CreateHaoDanwangList(res.data);
         resolve({data: ttt, pageIndex: res.min_id});
      }
    })
  })
}

function  JinDong(item) {
  return hotSearch.getSuperSearch_JinDong_Xiang(item.Category_name,AppConfig.ZhongHe,1)
  // return new  Promise(resolve => {
  //     const url = AppStore.data.jinDongApi.Similar + TimeStamp()
  //     var  data = {}
  //     data.pageNum = 1
  //     data.pageSize = 30
  //     var  dto = {}
  //     dto.sortMethod = 1
  //     dto.saleType = 10
  //     dto.orderByType = "desc"
  //     dto.cid=item.Cid
  //     dto.orderByColumn = 'buyCount'
  //     data.itemSearchDto = dto
  //
  //   axiosUtil.get(url,data).then(res=>{
  //     if (res.code !== '0'){
  //       viewUtil.ShowToast('服务器错误～');
  //     }else{
  //
  //       // console.log(res)
  //       var itemlist =   CreateJinDongXiangList(res.data.result)
  //       resolve({data: itemlist, pageIndex: res.data.nextPage});
  //     }
  //   })
  // })
}

function PingDuoDuo(item) {
  return hotSearch.getSuperSearch_PingDuoDuo(item.Category_name,AppConfig.ZhongHe,1)
}

